#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
typedef int LL;
const int maxn=100;
typedef pair<LL,LL>P;
inline LL read(){LL x=0,f=1;char ch=getchar();while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}return x*f;}
LL n,m;
vector<P>Be[maxn];
vector<P>El[maxn];
map<LL,LL>map1,map2;
void dfs1(LL u,LL dis){
    if(u==n){
        map1[dis]++;
        return;
    }
    for(LL i=0;i<Be[u].size();i++){
        P to=Be[u][i];
        LL v=to.first;LL cost=to.second;
        dfs1(v,dis+cost);
    }
}
void dfs2(LL u,LL dis){
    if(u==n){
        map2[dis]++;
        return;
    }
    for(LL i=0;i<El[u].size();i++){
        P to=El[u][i];
        LL v=to.first;LL cost=to.second;
        dfs2(v,dis+cost);
    }
}
int main(void)
{
    n=read();m=read();
    for(LL i=1;i<=m;i++){
        LL u,v,c,d;
        u=read();v=read();c=read();d=read();
        Be[u].push_back({v,c});
        El[u].push_back({v,d});
    }
    dfs1(1,0);
    dfs2(1,0);
    for(auto i:map1){
        LL num=i.first;
        if(map2.count(num)){
            cout<<num<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
return 0;
}
